<?php
/*
 * gallery class, loads/saves data (settings)
 *
 */
require_once('config_standard.php');
class Gallery {
	var $galleryName;
	var $galleryTitle;
	var $imageArraySorted;
	var $image2captionArray;

	/**
	 * constructor
	 *
	 * @return 	void
	 */
	function __construct($galleryName) {
		$this->galleryName = $galleryName;
		if ($maxHeight > 0 || $maxWide > 0) {
			$this->imageResource = $this->resizeImage($imagePath, $maxHeight, $maxWide);
		}
		$this->loadGalleryData($galleryName);
   }

	/**
	 * loads settings from gallery config file
	 *
	 * @param 	string	name of gallery
	 * @return 	void
	 */
	function loadGalleryData($galleryName){
		if (!isset($galleryName)) {
			return false;
		}
		global $c_galleryFolder;
		$configFile = ROOT . '/' . $c_galleryFolder . '/' . $galleryName . '/_gallery_config.php';
		if (file_exists($configFile)) {
			require_once($configFile);
		}
		$this->galleryName = $galleryName;
		$this->galleryTitle = $galleryTitle;
		$this->imageArraySorted = $imageArraySorted;
		$this->image2captionArray = $image2captionArray;
	}

	/**
	 * loads settings from gallery config file
	 *
	 * @param 	string	name of gallery
	 * @return 	bool	result
	 */
	static function isGallery($galleryName){
		if (!isset($galleryName)) {
			return false;
		}
		global $c_galleryFolder;
		if (is_dir(ROOT . '/' . $c_galleryFolder . '/' . $galleryName)) {
			return true;
		}
		return false;
	}

	/**
	 * get array of all gallery-folders
	 *
	 * @return 	array	gallery-folders
	 */
	static function getAllGalleries(){
		global $c_galleryFolder;
		if ($handle = opendir(ROOT . '/' . $c_galleryFolder)) {
		    while (false !== ($file = readdir($handle))) {
		        if (substr($file,0,1) != '.') {
		            $galleryArray[] = $file;
		        }
		    }
		    closedir($handle);
			return $galleryArray;
		}
		return false;
	}

}
?>